package com.zsy.controller;

import com.zsy.entity.ContractUser;
import com.zsy.entity.User;
import com.zsy.service.IContractService;
import com.zsy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
@RequestMapping("/contract")
public class ContractController {
    @Autowired
    private IContractService contractService;

    //查询当前用户信息
    @GetMapping("/getUsers")
    public Result getUsers(){
        return contractService.getUsers();
    }
    //修改用户信息
    @PostMapping("/updateUser")
    public Result updateUser(User user){
        System.out.println("修改数据："+user);
        return contractService.updateUser(user);
    }
    //修改用户密码
    @PostMapping("/updatePwd")
    public Result updatePwd(String password,String lowPassword){
        System.out.println("新密码："+password+"旧密码："+lowPassword);
        return contractService.updatePwd(password,lowPassword);
    }
    //查询当前用户所负责的合同
    @GetMapping("/selectContractAll")
    public Result selectContractAll(){
        return contractService.selectContractAll();
    }
    //添加合同记录
    @PostMapping("/addContract")
    public Result addContract(ContractUser contract){
        System.out.println(contract);
        return contractService.addContract(contract);
    }
    //查询已成功客户姓名
    @GetMapping("/getClientUserName")
    public Result getClientUserName(){
        return contractService.getClientUserName();
    }
    //统计销售合同额，销售合同数量
    @GetMapping("/getCount")
    public Result getCount(){
        return contractService.getCount();
    }
    //分页查询
    @PostMapping("/getLimit")
    public Result getLimit(int pagee,int index){
        return contractService.getLimit(pagee,index);
    }
    //批量删除
    @PostMapping("/delListContract")
    public Result delListContract(@RequestBody Integer[] ids){
        return contractService.delListContract(ids);
    }
    //上传
    @RequestMapping("/fileupload")
    public Result fileupload(MultipartFile uploadfile){
        System.out.println(uploadfile);
        return contractService.fileupload(uploadfile);
    }
    //下载
    @RequestMapping("/download")
    public ResponseEntity<byte[]> fileDownload(String filename){
        return contractService.fileDownload(filename);
    }
    //获取文件数据
    @GetMapping("/getFile")
    public Result getFile(){
        return contractService.getFile();
    }
    //获取头像
    @GetMapping("/getIco")
    public Result getIco(){
        return contractService.getIco();
    }


}
